#include <iostream>
#define byte char
void printBinary(char data);
byte *encode(char *exprossions);
char *decode(byte *data);
// 编码表达式
byte *encode(char *exprossions)
{
    char b1[2] = {22, 22};
    char b2 = 0;
    b2 = (char)(sizeof(exprossions) * 8);
    // b2 =
    std::cout << "encode!" << std::endl;
    byte *res = "encode";
    return res;
}

// 解码表达式
char *decode(byte *data)
{
    std::cout << "decode!" << std::endl;
    return "encode";
}

char parityCheck(char data)
{
    //1.获得1数量
    int num = 0;
    for (int i = 0; i < 8; i++)
    {
        char temp = data & (1 << i);
        if (temp != 0)
        {
            //数量+1
            num++;
        }
    }
    std::cout << "num:" << num << "\n";
    // 奇偶校验
    if (num % 2 == 0)
    {
        //如果最后一位是 1
        //1000 0000
        char temp = data & (1 << 7);
        if (temp != 0)
        {
            data &= (~(1 << 7));
        }
        else
        {
            data |= (1 << 7);
        }
    }
    return data;
}
void printBinary(char data)
{
    for (int i = 7; i >= 0; i--)
    {
        char temp = data & (1 << i);
        if (temp != 0)
        {
            std::cout << "1";
        }
        else
        {
            std::cout << "0";
        }
    }
    std::cout << "\n";
}
